package com.check.checksamejourney.controller;

import com.check.checksamejourney.bean.Search;
import com.check.checksamejourney.mapper.JourneyMapper;
import com.check.checksamejourney.response.BaseResponse;
import com.check.checksamejourney.response.JourneyDetailResult;
import com.check.checksamejourney.response.JourneySearchResult;
import com.check.checksamejourney.response.ResponseState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/journey")
public class JourneyController {

    @Autowired
    JourneyMapper journeyMapper;

    @GetMapping("/search")
    public BaseResponse<JourneySearchResult> search(String token, Search search){
        BaseResponse<JourneySearchResult> response = new BaseResponse<>();
        JourneySearchResult result = new JourneySearchResult();
        response.setResult(result);

        result.setJourneys(journeyMapper.getJourneys(search));

        response.setResponseState(ResponseState.SUCCESS);
        return response;
    }

    @GetMapping("/detail")
    public BaseResponse<JourneyDetailResult> detail(Long id){
        BaseResponse<JourneyDetailResult> response = new BaseResponse<>();
        JourneyDetailResult result = new JourneyDetailResult();
        response.setResult(result);

        result.setJourney(journeyMapper.getJourneyById(id));

        response.setResponseState(ResponseState.SUCCESS);
        return response;
    }

}
